package com.bigdata.spark.core.framework.service

import com.bigdata.spark.core.framework.common.TService
import com.bigdata.spark.core.framework.dao.WordCountDao
import org.apache.spark.rdd.RDD

/**
 * 服务层
 */
class WordCountService extends TService{

  private val wordCountDao = new WordCountDao()

  // 数据分析
  def dataAnalysis() ={

    val line = wordCountDao.readFile("datas/word.txt")

    val words: RDD[String] = line.flatMap(_.split(" "))
    val wordToOne: RDD[(String, Int)] = words.map(word => (word, 1))
    val wordToSum: RDD[(String, Int)] = wordToOne.reduceByKey(_ + _)
    val array = wordToSum.collect()
    array
  }
}
